﻿using CommunityToolkit.Mvvm.ComponentModel;
using Kang.Monitor.Wpf.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Kang.Monitor.Wpf.ViewModels
{
    internal class MainViewModel : BaseNotify
    {
        private UIElement _mainContent;

        public UIElement MainContent
        {
            get { return _mainContent; }
            set { SetProperty(ref _mainContent, value); }
        }

        public Command TabChangedCommand { get; }

        public MainViewModel()
        {
            TabChangedCommand = new Command(doTabChanged);
            onInit();
        }

        private void onInit()
        {
            doTabChanged("Kang.Monitor.Wpf | Kang.Monitor.Wpf.Views.IndexView");
        }

        private void doTabChanged(object arg)
        {
            string[] strValues = arg.ToString().Split('|', StringSplitOptions.RemoveEmptyEntries);
            Assembly assembly = Assembly.LoadFrom(strValues[0].Trim() + ".dll");
            Type type = assembly.GetType(strValues[1].Trim());
            this.MainContent = (UIElement)Activator.CreateInstance(type);
        }
    }
}